package com.example.light.base;

import com.example.light.common.exception.GlobalException;
import com.example.light.common.result.CodeMsg;
import com.example.light.web.meeting.entity.OaRoom;
import com.example.light.web.meeting.service.MeetService;
import com.example.light.web.meeting.service.OaMachineService;
import com.example.light.web.meeting.service.OaRoomService;
import com.example.light.web.meeting.vo.MeetRecordVO;
import com.example.light.web.system.entity.Role;
import com.example.light.web.system.entity.RolePerm;
import com.example.light.web.system.entity.User;
import com.example.light.web.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author bengang
 * @date 2018/8/27
 * @time 10:24
 * @description 页面跳转控制器
 */
@Controller
public class BaseHomeController {

    @Autowired
    @Qualifier("userServiceImpl")
    private UserService userService;

    @Autowired
    private OaRoomService roomService;

    @Autowired
    private MeetService meetService;

    @Autowired
    private OaMachineService machineService;

    //---------------- 用户登录/注册跳转 ----------------
    @RequestMapping("toIndex")
    public String toIndex(HttpSession session, User user){
//        User user = userService.getUser();
//        session
        if(user == null){
            throw new GlobalException(CodeMsg.SystemCodeMsg.USER_NOT_LOGIN);
        }
        Role role = userService.selectUserRole(user.getUserId());
        Integer []permIdS=userService.selectPermId(role.getRoleId());
        if(role != null){
            session.setAttribute("role",role.getRoleName());
            session.setAttribute("permIds",permIdS);
        }
        session.setAttribute("user",user);

        return "index";
    }
    @RequestMapping("")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("toRegister")
    public String register() {
        return "register";
    }

    //---------------会议室管理登录----------------------------
    @RequestMapping("toRoom")
    public String meetRoomList(Model model) {
        roomService.roomList(model);
        return "meeting/meet_room/meeting_room_manage";
    }

    @RequestMapping("toAddRoom")
    String addRoom() {
        return "meeting/meet_room/meeting_room_add";
    }
    //----------------设备管理-----------------------------------------
    @RequestMapping("toMachine")
    String toMachine(Model model){
        machineService.machineList(model);
        return "meeting/meet_room/device_manage";
    }
    @RequestMapping("toAddMachine")
    String toAddMachine(){
        return "meeting/meet_room/device_add";
    }


}
